/**
 * 结算方式管理
 */
Ext.namespace('Divo');
Ext.namespace('Divo.app');

Divo.app.LicensesList = function() {
  /* ----------------------- private属性 ----------------------- */
  var canEdit = false, status = "list"; // 当前列表状态("list","insert","edit")
  var gridEl = 'Person-grid';
  var gridAdd;
  var grid, grid2, form1, form2, selModel, dModel, toolbar1, toolbar2, win1, win2;
  var data, data2, data3, sId;
  var grid3, form3, selModel3, toolbar3, win3;
  var inputText, supplierId, supplier;
  var upWin1, upWin2, upWin3, uploadForm1, uploadForm2, uploadForm3;
  var picWin1, picWin2, picWin3, updateButton1, updateButton2, updateButton3;
  /* ----------------------- private方法 ----------------------- */
  // 创建列表
  function createGrid() {
    var queryFlds = new Array();
    var searchFlds = new Ext.util.MixedCollection();
    queryFlds.push('supplier');
    var fldName = new Ext.form.TextField({
          name : 'supplier',
          id : gridEl + '-supplier',
          fieldLabel : '名称',
          allowBlank : true,
          width : 100

        });
    searchFlds.add('supplier', fldName);

    grid = new Divo.Base.GridView({
          remoteSort : true,
          gridId : gridEl,
          queryFlds : queryFlds,
          searchFlds : searchFlds,
          hasBbar : false,
          entityClassName : 'com.our.sys.project1.entity.Businesslicence',
          queryUrl : 'licenses/query_b',
          deleteUrl : 'licenses/delete_b',
          jsonId : 'id',
          recordPk : ["id"]
        });
    selModel = grid.getSelectionModel();
    selModel.on('rowselect', onRowSelect);

    grid.on('cellclick', function(grid, rowIndex, columnIndex, e) {
          var fld = grid.getColumnModel().getColumnHeader(columnIndex);
          if (fld == '供应商名称') {

          }
        }, this, true);

    grid2 = new Divo.Base.GridView({
          hasBbar : true,
          remoteSort : true,
          gridId : queryFlds,
          searchFlds : searchFlds,
          hasBbar : false,
          entityClassName : 'com.our.sys.project1.entity.Produclicenses',
          queryUrl : 'licenses/query_p',
          deleteUrl : 'licenses/delete_p',
          jsonId : 'id',
          recordPk : ["id"]
        });

    dModel = grid2.getSelectionModel();
    dModel.on('rowselect', onDRowSelect);

    grid3 = new Divo.Base.GridView({
          hasBbar : true,
          remoteSort : true,
          gridId : queryFlds,
          searchFlds : searchFlds,
          hasBbar : false,
          entityClassName : 'com.our.sys.project1.entity.Medicallicenses',
          queryUrl : 'licenses/query_m',
          deleteUrl : 'licenses/delete_m',
          jsonId : 'id',
          recordPk : ["id"]
        });

    selModel3 = grid3.getSelectionModel();
    selModel3.on('rowselect', onDRowSelect3);
    grid.getStore().on('beforeload', function(store, options) {
          store.baseParams.supplierId = supplierId ? supplierId : '';
        }, this, true);
    grid2.getStore().on('beforeload', function(store, options) {
          store.baseParams.supplierId = supplierId ? supplierId : '';
        }, this, true);
    grid3.getStore().on('beforeload', function(store, options) {
          store.baseParams.supplierId = supplierId ? supplierId : '';
        }, this, true);
    var cm = grid.getColumnModel();
    for (i = 0; i < cm.getColumnCount(); i++) {

    }

    var cm2 = grid2.getColumnModel();
    for (i = 0; i < cm2.getColumnCount(); i++) {

    }
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "float"
        }, {
          name : "name",
          type : "string"
        }]);
    var storeDs = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'supplier/query'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });
    inputText = new app.base.ComboBox({
          id : 'combo-supplier-text',
          name : "supplier",
          dataIndex : "supplier",
          fieldLabel : '选择供应商',
          store : storeDs,
          displayField : 'name',
          valueField : 'id',
          forceSelection : true,
          mode : 'remote',
          triggerAction : 'all',
          editable : false,
          allowBlank : false,
          labelSeparator : ":*",
          selectOnFocus : true,
          width : 150,
          insert_allowed : true,
          update_allowed : true,
          onSelect : function(record) {
            var data = record.data;
            this.setValue(data.name);
            supplierId = data.id;
            supplier = data.name;
            grid.getStore().load();
            grid2.getStore().load();
            grid3.getStore().load();
            this.onTriggerClick();
          }
        });

    uploadForm1 = new Ext.form.FormPanel({
      baseCls : 'x-plain',
      labelWidth : 70,
      fileUpload : true,
      defaultType : 'textfield',
      items : [{
        xtype : 'textfield',
        fieldLabel : '上传文件名',
        name : 'userfile',
        id : 'userfile',
        inputType : 'file',
        blankText : 'File can\'t not empty.',
        anchor : '100%',
        listeners : {
          'render' : function() {
            var logoFileCmp = Ext.get('userfile');
            logoFileCmp.on('change', function(field, newValue, oldValue) {
              var picPath = logoFileCmp.getValue();
              var url = 'file:///' + picPath;
              if (Ext.isIE) {
                if (null != Ext.get('logoPic1')) {
                  var image1 = Ext.get('logoPic1').dom;
                  image1.src = Ext.BLANK_IMAGE_URL;
                  image1.filters
                      .item("DXImageTransform.Microsoft.AlphaImageLoader").src = url;
                }
              } else {
                // 支持FF
                if (null != Ext.get('logoPic1')) {
                  Ext.get('logoPic1').dom.src = Ext.get('userfile').dom.files
                      .item(0).getAsDataURL();
                }
              }
            }, this);
          }
        }
      }]
    });
    
    uploadForm2 = new Ext.form.FormPanel({
      baseCls : 'x-plain',
      labelWidth : 70,
      fileUpload : true,
      defaultType : 'textfield',
      items : [{
        xtype : 'textfield',
        fieldLabel : '上传文件名',
        name : 'userfile',
        id : 'userfile2',
        inputType : 'file',
        blankText : 'File can\'t not empty.',
        anchor : '100%',
        listeners : {
          'render' : function() {
            var logoFileCmp = Ext.get('userfile2');
            logoFileCmp.on('change', function(field, newValue, oldValue) {
              var picPath = logoFileCmp.getValue();
              var url = 'file:///' + picPath;
              if (Ext.isIE) {
                if (null != Ext.get('logoPic2')) {
                  var image1 = Ext.get('logoPic2').dom;
                  image1.src = Ext.BLANK_IMAGE_URL;
                  image1.filters
                      .item("DXImageTransform.Microsoft.AlphaImageLoader").src = url;
                }
              } else {
                // 支持FF
                if (null != Ext.get('logoPic2')) {
                  Ext.get('logoPic2').dom.src = Ext.get('userfile2').dom.files
                      .item(0).getAsDataURL();
                }
              }
            }, this);
          }
        }
      }]
    });
    
    uploadForm3 = new Ext.form.FormPanel({
      baseCls : 'x-plain',
      labelWidth : 70,
      fileUpload : true,
      defaultType : 'textfield',
      items : [{
        xtype : 'textfield',
        fieldLabel : '上传文件名',
        name : 'userfile',
        id : 'userfile3',
        inputType : 'file',
        blankText : 'File can\'t not empty.',
        anchor : '100%',
        listeners : {
          'render' : function() {
            var logoFileCmp = Ext.get('userfile3');
            logoFileCmp.on('change', function(field, newValue, oldValue) {
              var picPath = logoFileCmp.getValue();
              var url = 'file:///' + picPath;
              if (Ext.isIE) {
                if (null != Ext.get('logoPic3')) {
                  var image1 = Ext.get('logoPic3').dom;
                  image1.src = Ext.BLANK_IMAGE_URL;
                  image1.filters
                      .item("DXImageTransform.Microsoft.AlphaImageLoader").src = url;
                }
              } else {
                // 支持FF
                if (null != Ext.get('logoPic3')) {
                  Ext.get('logoPic3').dom.src = Ext.get('userfile3').dom.files
                      .item(0).getAsDataURL();
                }
              }
            }, this);
          }
        }
      }]
    });

    updateButton1 = new Ext.Button({
          id : 'upload_button1',
          text : '上传',
          handler : function() {
            uploadForm1.getForm().submit({
                  url : "licenses/save_img",
                  method : 'POST',
                  waitTitle : '请稍后',
                  waitMsg : '正在上传文件 ...',
                  success : function(fp, action) {
                    var filePath = action.result.filePath;
                    Ext.Msg.alert('成功！', '上传成功！');
                    Ext.Ajax.request({
                          params : {
                            filePath : filePath,
                            id : data.id
                          },
                          url : "licenses/save_img_src_1",
                          callback : function(o, s, r) {
                            var respText = Ext.decode(r.responseText);
                            if (respText.success) {
                              upWin1.hide();
                            } else {
                              if (respText.message.length > 0)
                                Ext.Msg.alert('错误', respText.message);
                            }
                          }
                        });
                  },
                  failure : function(fp, action) {
                    Ext.Msg.alert('失败！', '文件上传失败！');
                  }
                });
          }
        });

    updateButton2 = new Ext.Button({
          id : 'upload_button2',
          text : '上传',
          handler : function() {
            uploadForm2.getForm().submit({
                  url : "licenses/save_img",
                  method : 'POST',
                  waitTitle : '请稍后',
                  waitMsg : '正在上传文件 ...',
                  success : function(fp, action) {
                    var filePath = action.result.filePath;
                    Ext.Msg.alert('成功！', '上传成功！');
                    Ext.Ajax.request({
                          params : {
                            filePath : filePath,
                            id : data2.id
                          },
                          url : "licenses/save_img_src_2",
                          callback : function(o, s, r) {
                            var respText = Ext.decode(r.responseText);
                            if (respText.success) {
                              upWin2.hide();
                            } else {
                              if (respText.message.length > 0)
                                Ext.Msg.alert('错误', respText.message);
                            }
                          }
                        });
                  },
                  failure : function(fp, action) {
                    Ext.Msg.alert('失败！', '文件上传失败！');
                  }
                });
          }
        });

    updateButton3 = new Ext.Button({
          id : 'upload_button3',
          text : '上传',
          handler : function() {
            uploadForm3.getForm().submit({
                  url : "licenses/save_img",
                  method : 'POST',
                  waitTitle : '请稍后',
                  waitMsg : '正在上传文件 ...',
                  success : function(fp, action) {
                    var filePath = action.result.filePath;
                    Ext.Msg.alert('成功！', '上传成功！');
                    Ext.Ajax.request({
                          params : {
                            filePath : filePath,
                            id : data3.id
                          },
                          url : "licenses/save_img_src_3",
                          callback : function(o, s, r) {
                            var respText = Ext.decode(r.responseText);
                            if (respText.success) {
                              upWin3.hide();
                            } else {
                              if (respText.message.length > 0)
                                Ext.Msg.alert('错误', respText.message);
                            }
                          }
                        });
                  },
                  failure : function(fp, action) {
                    Ext.Msg.alert('失败！', '文件上传失败！');
                  }
                });
          }
        });
  }

  function onDRowSelect(selModel, rowIndex, record) {
    data2 = record.data;
  }

  function onDRowSelect3(selModel, rowIndex, record) {
    data3 = record.data;
  }
  // 选择某行
  function onRowSelect(selModel, rowIndex, record) {
    data = record.data;
    sId = data.id;
    canEdit = 'N';
    status = "list";
    // setToolbarStatus();
    // grid2.getStore().reload();
  }

  // 刷新列表
  function reloadRecords() {
    grid.getStore().reload();
    status = "list";
    // setToolbarStatus();
  }
  function reloadRecord2() {
    grid2.getStore().reload();
  }
  function reloadRecord3() {
    grid3.getStore().reload();
  }
  // 创建新的记录，初始化表单
  function createNewRecord() {
    if (supplierId == null || supplierId == "") {
      Ext.Msg.alert('错误', "请选供应商！");
      return;
    }
    form.loadRecord(new form.dataRecordMeta({
          _p_record_status : "insert",
          id : "",
          supplierId : supplierId,
          supplier : supplier,
          copyNo : "",
          registerNo : "",
          address : "",
          registerMoney : "",
          person : "",
          companyType : "",
          businessRange : "",
          setUpDate : "",
          businessLast : "",
          yearCheck : ""
        }));
    win = new Ext.Window({
          title : '新增营业执照',
          iconCls : 'icon-win',
          autoHeight : true,
          width : 360,
          layout : 'form',
          plain : false,
          buttonAlign : 'right',
          closable : false,
          modal : true,
          items : [form]
        });
    var yesBtn = win.addButton({
          text : '确定'
        }, commitForm, this);
    var cancelBtn = win.addButton({
          text : '关闭'
        }, onWinHide, this);

    win.show();
  }
  function onWinHide() {
    win.hide();
  }
  // 创建新的记录，初始化表单
  function createRecords() {
    if (supplierId == null || supplierId == "") {
      Ext.Msg.alert('错误', "请选供应商！");
      return;
    }
    form2.loadRecord(new form2.dataRecordMeta({
          _p_record_status : "insert",
          id : "",
          supplierId : supplierId,
          supplier : supplier,
          produceId : "",
          produce : "",
          produceNo : "",
          registerAddress : "",
          produceAddress : "",
          registerMoney : "",
          person : "",
          companyPerson : "",
          businessRange : "",
          licensDate : "",
          endDate : "",
          licensesOrg : ""
        }));
    win2 = new Ext.Window({
          title : '新增生产经营许可证',
          iconCls : 'icon-win',
          autoHeight : true,
          width : 360,
          layout : 'form',
          plain : false,
          buttonAlign : 'right',
          closable : false,
          modal : true,
          items : [form2]
        });
    var yesBtn = win2.addButton({
          text : '确定'
        }, commitbankForm, this);
    var cancelBtn = win2.addButton({
          text : '关闭'
        }, onbankwinHide, this);

    win2.show();
  }

  function onbankwinHide() {
    win2.hide();
  }

  function createRecords3() {
    if (supplierId == null || supplierId == "") {
      Ext.Msg.alert('错误', "请选供应商！");
      return;
    }
    form3.loadRecord(new form3.dataRecordMeta({
          _p_record_status : "insert",
          id : "",
          supplierId : supplierId,
          supplier : supplier,
          produceId : "",
          produce : "",
          shortName : "",
          registerNo : "",
          highValueAllName : "",
          highValueItemName : "",
          checkDate : "",
          endDate : ""

        }));
    win3 = new Ext.Window({
          title : '新增医疗器材许可证',
          iconCls : 'icon-win',
          autoHeight : true,
          width : 360,
          layout : 'form',
          plain : false,
          buttonAlign : 'right',
          closable : false,
          modal : true,
          items : [form3]
        });
    var yesBtn = win3.addButton({
          text : '确定'
        }, commitbankForm3, this);
    var cancelBtn = win3.addButton({
          text : '关闭'
        }, onbankwinHide3, this);

    win3.show();
  }

  function onbankwinHide3() {
    win3.hide();
  }

  // 切换记录编辑状态
  function EditMode2() {
    form2.loadRecord(new form2.dataRecordMeta({
          _p_record_status : "insert",
          id : data2.id,
          supplierId : data2.supplierId,
          supplier : data2.supplier,
          produceId : data2.produceId,
          produce : data2.produce,
          produceNo : data2.produceNo,
          registerAddress : data2.registerAddress,
          produceAddress : data2.produceAddress,
          registerMoney : data2.registerMoney,
          person : data2.person,
          companyPerson : data2.companyPerson,
          businessRange : data2.businessRange,
          licensDate : data2.licensDate,
          endDate : data2.endDate,
          licensesOrg : data2.licensesOrg
        }));
    win2 = new Ext.Window({
          title : '编辑二级科目信息',
          iconCls : 'icon-win',
          autoHeight : true,
          width : 360,
          layout : 'form',
          plain : false,
          buttonAlign : 'right',
          closable : false,
          modal : true,
          items : [form2]
        });
    var yesBtn = win2.addButton({
          text : '确定'
        }, commitbankForm, this);
    var cancelBtn = win2.addButton({
          text : '关闭'
        }, onbankwinHide, this);

    win2.show();
  }
  // 创建form表单
  function createForm() {
    form = new Divo.app.BusinesslicenceForm({
          layout : 'fit',
          region : 'east',
          border : true,
          split : true,
          width : 320,
          minSize : 300,
          maxSize : 400,
          submitUrl : 'licenses/save_b'
        });

    form.on('commitFormSuccess', afterCommitFormSuccess);

    form2 = new Divo.app.ProduclicensesForm({
          layout : 'fit',
          region : 'east',
          border : true,
          split : true,
          width : 350,
          minSize : 300,
          maxSize : 400,
          submitUrl : 'licenses/save_p'
        });

    form2.on('commitFormSuccess', afterCommitFormSuccess2);

    form3 = new Divo.app.MedicallicensesForm({
          layout : 'fit',
          region : 'east',
          border : true,
          split : true,
          width : 350,
          minSize : 300,
          maxSize : 400,
          submitUrl : 'licenses/save_m'
        });

    form3.on('commitFormSuccess', afterCommitFormSuccess3);
  }

  // 新建或修改表单成功提交后,重新加载其父节点
  function afterCommitFormSuccess(operation, recordData) {
    grid.getStore().reload();
  }

  function afterCommitFormSuccess2(operation, recordData) {
    grid2.getStore().reload();
  }

  function afterCommitFormSuccess3(operation, recordData) {
    grid3.getStore().reload();
  }

  function showUpWin1() {
    var sel = selModel.getSelections();
    if (sel.length <= 0) {
      Ext.Msg.alert('错误', "请选择一条记录！");
      return;
    }
    upWin1 = new Ext.Window({
      title : '供应商三证',
      iconCls : 'icon-win',
      autoHeight : true,
      width : 700,
      layout : 'column',
      plain : false,
      buttonAlign : 'right',
      closable : false,
      modal : true,
      items : [{
        xtype : 'box',
        id : 'logoPic1',
        width : 700,
        height : 400,
        autoEl : {
          tag : 'img',
          src : data == null ? Ext.BLANK_IMAGE_URL : data.imgSrc,
          style : 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);'
        }
      }, uploadForm1, updateButton1]
    });
    var cancelBtn = upWin1.addButton({
          text : '关闭'
        }, function() {
          upWin1.hide();
        }, this);
    upWin1.show();
  }

  function showUpWin2() {
    var sel = dModel.getSelections();
    if (sel.length <= 0) {
      Ext.Msg.alert('错误', "请选择一条记录！");
      return;
    }
    upWin2 = new Ext.Window({
      title : '供应商三证',
      iconCls : 'icon-win',
      autoHeight : true,
      width : 700,
      layout : 'column',
      plain : false,
      buttonAlign : 'right',
      closable : false,
      modal : true,
      items : [{
        xtype : 'box',
        id : 'logoPic2',
        width : 700,
        height : 400,
        autoEl : {
          tag : 'img',
          src : data2 == null ? Ext.BLANK_IMAGE_URL : data2.imgSrc,
          style : 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);'
        }
      }, uploadForm2, updateButton2]
    });
    var cancelBtn = upWin2.addButton({
          text : '关闭'
        }, function() {
          upWin2.hide();
        }, this);
    upWin2.show();
  }

  function showUpWin3() {
    var sel = selModel3.getSelections();
    if (sel.length <= 0) {
      Ext.Msg.alert('错误', "请选择一条记录！");
      return;
    }
    upWin3 = new Ext.Window({
      title : '供应商三证',
      iconCls : 'icon-win',
      autoHeight : true,
      width : 700,
      layout : 'column',
      plain : false,
      buttonAlign : 'right',
      closable : false,
      modal : true,
      items : [{
        xtype : 'box',
        id : 'logoPic3',
        width : 700,
        height : 400,
        autoEl : {
          tag : 'img',
          src : data3 == null ? Ext.BLANK_IMAGE_URL : data3.imgSrc,
          style : 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);'
        }
      }, uploadForm3, updateButton3]
    });
    var cancelBtn = upWin3.addButton({
          text : '关闭'
        }, function() {
          upWin3.hide();
        }, this);
    upWin3.show();
  }

  // 创建layout
  function createLayout() {
    toolbar = new Ext.Toolbar({
          items : ["供应商：", inputText, {
                icon : "resources/img/g_rec_new.png",
                text : "新增",
                id : "tlb_NEW1",
                handler : createNewRecord
              }, {
                icon : "resources/img/g_rec_del.png",
                text : "删除",
                id : "tlb_DELETE1",
                handler : deleteRecord
              }, '-', {
                icon : "resources/img/g_rec_upd.png",
                text : "编辑",
                id : "tlb_EDIT1",
                handler : toggleEditMode
              }, '-', {
                icon : "resources/img/g_rec_upd.png",
                text : "上传证书",
                id : "tlb_UPLOAD1",
                handler : showUpWin1
              }, {
                icon : "resources/img/g_rec_refresh.gif",
                text : "刷新",
                id : "tlb_REFRESH1",
                handler : reloadRecords
              }]
        });
    toolbar2 = new Ext.Toolbar({
          items : [{
                icon : "resources/img/g_rec_new.png",
                text : "新增",
                id : "tlb_NEWSS2",
                handler : createRecords
              }, {
                icon : "resources/img/g_rec_del.png",
                text : "删除",
                id : "tlb_DELETESS2",
                handler : deleteRecordbank
              }, '-', {
                icon : "resources/img/g_rec_upd.png",
                text : "编辑",
                id : "tlb_EDITSS2",
                handler : EditMode2
              }, '-', {
                icon : "resources/img/g_rec_upd.png",
                text : "上传证书",
                id : "tlb_UPLOAD2",
                handler : showUpWin2
              }, {
                icon : "resources/img/g_rec_refresh.gif",
                text : "刷新",
                id : "tlb_REFRESHSS2",
                handler : reloadRecord2
              }]
        });
    toolbar3 = new Ext.Toolbar({
          items : [{
                icon : "resources/img/g_rec_new.png",
                text : "新增",
                id : "tlb_NEWSS3",
                handler : createRecords3
              }, {
                icon : "resources/img/g_rec_del.png",
                text : "删除",
                id : "tlb_DELETESS3",
                handler : deleteRecordbank3
              }, '-', {
                icon : "resources/img/g_rec_upd.png",
                text : "编辑",
                id : "tlb_EDITSS3",
                handler : toggleEditMode3
              }, '-', {
                icon : "resources/img/g_rec_upd.png",
                text : "上传证书",
                id : "tlb_UPLOAD3",
                handler : showUpWin3
              }, {
                icon : "resources/img/g_rec_refresh.gif",
                text : "刷新",
                id : "tlb_REFRESHSS3",
                handler : reloadRecord3
              }]
        });
    var viewport = new Ext.Viewport({
          layout : 'border',
          items : [{
                layout : 'border',
                region : 'center',
                border : false,
                items : [{
                      layout : 'border',
                      region : 'north',
                      border : false,
                      height : 160,
                      items : [{
                            layout : 'fit',
                            region : 'north',
                            border : false,
                            items : [toolbar],
                            height : 25
                          }, {
                            layout : 'fit',
                            region : 'center',
                            border : false,
                            items : [grid]
                          }]
                    }, {
                      layout : 'border',
                      region : 'center',
                      border : false,
                      items : [{
                            layout : 'border',
                            region : 'north',
                            border : false,
                            height : 170,
                            items : [{
                                  layout : 'fit',
                                  region : 'north',
                                  border : false,
                                  items : [toolbar2],
                                  height : 25
                                }, {
                                  layout : 'fit',
                                  region : 'center',
                                  border : false,
                                  items : [grid2]
                                }]
                          }, {
                            layout : 'border',
                            region : 'center',
                            border : false,
                            items : [{
                                  layout : 'fit',
                                  region : 'north',
                                  border : false,
                                  items : [toolbar3],
                                  height : 25
                                }, {
                                  layout : 'fit',
                                  region : 'center',
                                  border : false,
                                  items : [grid3]
                                }]
                          }]
                    }]
              }]
        });

    viewport.doLayout();
  }

  // 删除记录
  function deleteRecord() {
    grid.deleteRecord();
  }
  // 删除记录
  function deleteRecordbank() {
    grid2.deleteRecord();
  }

  function deleteRecordbank3() {
    grid3.deleteRecord();
  }
  // 切换过滤查询工具条状态
  function toggleFilterBar() {
    grid.toggleFilterBar();
  }

  // 切换记录编辑状态
  function toggleEditMode() {
    form.loadRecord(new form.dataRecordMeta({
          _p_record_status : "insert",
          id : data.id,
          supplierId : data.supplierId,
          supplier : data.supplier,
          copyNo : data.copyNo,
          registerNo : data.registerNo,
          address : data.address,
          registerMoney : data.registerMoney,
          person : data.person,
          companyType : data.companyType,
          businessRange : data.businessRange,
          setUpDate : data.setUpDate,
          businessLast : data.businessLast,
          yearCheck : data.yearCheck
        }));
    win = new Ext.Window({
          title : '编辑营业执照',
          iconCls : 'icon-win',
          autoHeight : true,
          width : 320,
          layout : 'form',
          plain : false,
          buttonAlign : 'right',
          closable : false,
          modal : true,
          items : [form]
        });
    var yesBtn = win.addButton({
          text : '确定'
        }, commitForm, this);
    var cancelBtn = win.addButton({
          text : '关闭'
        }, onWinHide, this);

    win.show();
  }

  // 切换记录编辑状态
  function toggleEditMode3() {
    form3.loadRecord(new form3.dataRecordMeta({
          _p_record_status : "insert",
          id : data3.id,
          supplierId : data3.supplierId,
          supplier : data3.supplier,
          produceId : data3.produceId,
          produce : data3.produce,
          shortName : data3.shortName,
          registerNo : data3.registerNo,
          highValueAllName : data3.highValueAllName,
          highValueItemName : data3.highValueItemName,
          checkDate : data3.checkDate,
          endDate : data3.endDate
        }));
    win3 = new Ext.Window({
          title : '编辑医疗器材许可证',
          iconCls : 'icon-win',
          autoHeight : true,
          width : 320,
          layout : 'form',
          plain : false,
          buttonAlign : 'right',
          closable : false,
          modal : true,
          items : [form3]
        });
    var yesBtn = win3.addButton({
          text : '确定'
        }, commitbankForm3, this);
    var cancelBtn = win3.addButton({
          text : '关闭'
        }, onbankwinHide3, this);

    win3.show();
  }

  // 提交表单，保存新建或修改的信息
  function commitForm() {
    form.commitForm();
    win.hide();
  }
  function commitbankForm() {
    form2.commitForm();
    win2.hide();
  }
  function commitbankForm3() {
    form3.commitForm();
    win3.hide();
  }
  // 加载数据完成后
  function onLoad(store, records, options) {
    status = "list";
    // setToolbarStatus();
  }

  // 设置工具条状态
  function setToolbarStatus() {
    if (status == "list") {
      toolbar.items.get("tlb_NEW").enable();
      if (canEdit) {
        toolbar.items.get("tlb_DELETE").enable();
        toolbar.items.get("tlb_EDIT").enable();
      } else {
        toolbar.items.get("tlb_DELETE").disable();
        toolbar.items.get("tlb_EDIT").disable();
      }
    } else {
      toolbar.items.get("tlb_NEW").disable();
      toolbar.items.get("tlb_DELETE").disable();
      toolbar.items.get("tlb_EDIT").disable();
    }

    if (!Divo.util.Tools.checkUserEdit()) {
      toolbar.items.get("tlb_NEW").disable();
      toolbar.items.get("tlb_DELETE").disable();
      toolbar.items.get("tlb_EDIT").disable();
    }
  }

  /* ----------------------- public方法 ----------------------- */
  return {
    /**
     * 初始化
     */
    init : function() {
      createGrid();
      createForm();
      createLayout();
      grid.load();
      grid.getStore().on("load", onLoad);
    }
  }
}();

Ext.onReady(Divo.app.LicensesList.init, Divo.app.LicensesList, true);